<?php
//程序错误日志
define('DEF_BASE_LOG_PATH', dirname(__FILE__)."/logs/");
/**
 * 日志类
 * 
 * @copyright	(c) 2012, 博华信智  All rights reserved.
 * @author 	jinhuayun
 * @version	1.0.1.1 - 2012-03-08
 * @package	log
 */

class Log
{
    const ERR     = 3;  // Error: error conditions
    const WARN    = 4;  // Warning: warning conditions
    const INFO    = 6;  // Informational: informational messages
    const DEBUG   = 7;  // Debug: debug messages

	//写入日志
	static public function addLogs($logConten, $logType = Log::ERR, $module="default")
	{
		$log_file_path = Log::getLogFilePath($logType, $module);
		$log_file_name = $log_file_path . date("Y-m-d") . ".log";

		$logConten .= "\n";
		$ret = file_put_contents($log_file_name, $logConten, FILE_APPEND);
	}

	static private function getLogFilePath($logType,$module)
	{
		$logTypeDir = "";
		switch ($logType)
		{
			case Log::ERR:
				$logTypeDir = "ERR";
				break;
			case Log::WARN:
				$logTypeDir = "WARN";
				break;
			case Log::INFO:
				$logTypeDir = "INFO";
				break;
			case Log::DEBUG:
				$logTypeDir = "DEBUG";
				break;
			default:
				$logTypeDir = "INFO";
		}
		$path = DEF_BASE_LOG_PATH . $logTypeDir . "/";
		if (!file_exists($path)){
			mkdir($path,755,true);
		}
		if($logType == Log::INFO){
			$module = $module ? $module : "default";
			$path .= strtolower($module)."/";
			if (!file_exists($path)){
				mkdir($path,755,true);
			}
		}
		return $path;
	}
}


?>